package top.glike.funct.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.glike.common.annotation.Log;
import top.glike.common.core.controller.BaseController;
import top.glike.common.core.domain.AjaxResult;
import top.glike.common.enums.BusinessType;
import top.glike.funct.domain.BedFile;
import top.glike.funct.service.IBedFileService;
import top.glike.common.utils.poi.ExcelUtil;
import top.glike.common.core.page.TableDataInfo;

/**
 * 图床文件Controller
 * 
 * @author Sophia
 * @date 2024-03-07
 */
@RestController
@RequestMapping("/bed/file")
public class BedFileController extends BaseController
{
    @Autowired
    private IBedFileService bedFileService;

    /**
     * 查询图床文件列表
     */
    @PreAuthorize("@ss.hasPermi('bed:file:list')")
    @GetMapping("/list")
    public TableDataInfo list(BedFile bedFile)
    {
        startPage();
        List<BedFile> list = bedFileService.selectBedFileList(bedFile);
        return getDataTable(list);
    }

    /**
     * 导出图床文件列表
     */
    @PreAuthorize("@ss.hasPermi('bed:file:export')")
    @Log(title = "图床文件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BedFile bedFile)
    {
        List<BedFile> list = bedFileService.selectBedFileList(bedFile);
        ExcelUtil<BedFile> util = new ExcelUtil<BedFile>(BedFile.class);
        util.exportExcel(response, list, "图床文件数据");
    }

    /**
     * 获取图床文件详细信息
     */
    @PreAuthorize("@ss.hasPermi('bed:file:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bedFileService.selectBedFileById(id));
    }

    /**
     * 新增图床文件
     */
    @PreAuthorize("@ss.hasPermi('bed:file:add')")
    @Log(title = "图床文件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BedFile bedFile)
    {
        return toAjax(bedFileService.insertBedFile(bedFile));
    }

    /**
     * 修改图床文件
     */
    @PreAuthorize("@ss.hasPermi('bed:file:edit')")
    @Log(title = "图床文件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BedFile bedFile)
    {
        return toAjax(bedFileService.updateBedFile(bedFile));
    }

    /**
     * 删除图床文件
     */
    @PreAuthorize("@ss.hasPermi('bed:file:remove')")
    @Log(title = "图床文件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bedFileService.deleteBedFileByIds(ids));
    }
}
